First(TSource) Method (ParallelQuery(TSource), Func(TSource, Boolean))

Task Parallel System.Threading

Returns the first element in a parallel sequence that satisfies a specified condition.

Namespace:  System.Linq
Assembly:  System.Threading (in System.Threading.dll)

Syntax

Visual Basic (Declaration)
Public Shared Function First(Of TSource) ( _
	source As ParallelQuery(Of TSource), _
	predicate As Func(Of TSource, Boolean) _
) As TSource
C#
public static TSource First<TSource>(
	ParallelQuery<TSource> source,
	Func<TSource, bool> predicate
)

Parameters

source
Type: System.Linq..::.ParallelQuery<(Of <(TSource>)>)
The sequence to return an element from.
predicate
Type: System..::.Func<(Of <(TSource, Boolean>)>)
A function to test each element for a condition.

Type Parameters

TSource
The type of the elements of source.

Return Value

The first element in the sequence that passes the test in the specified predicate function.

Remarks

There's a temporary difference from LINQ to Objects, this does not throw ArgumentNullException when the predicate is null.

Exceptions

ExceptionCondition
System..::.ArgumentNullException source or predicate is a null reference (Nothing in Visual Basic).
System..::.InvalidOperationException No element in source satisfies the condition in predicate.
System..::.AggregateException One or more exceptions occurred during the evaluation of the query.
System..::.OperationCanceledException The query was canceled.

See Also